//-----------------------------------------------------------------------------
// Name: BulletManager.cpp
// Auth: Paul Godfrey
// Desc: Keeps a list of Bullets
//-----------------------------------------------------------------------------


#include "BulletManager.h"
#include "Bullet.h"
#include <iostream>
#include <windows.h>
using namespace std;
cBulletManager gBulletManager;


//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cBulletManager* GetBulletManager()
{
	return &gBulletManager;
}

cBulletManager::cBulletManager()
{

}

cBulletManager::~cBulletManager()
{
}

//Adds one bullet to the manager - queue position is irrelevent so it always adds to the front.
void cBulletManager::addBullet(float x, float Yy, float z, float y, float p, int d)
{
	cBullet* newBullet = new cBullet(x,Yy,z,y,p,d, 100.0f);

	liBullets.push_back(*newBullet);
}

void cBulletManager::addVaccineBullet(float x, float Yy, float z, float y, float p, int d)
{
	cBullet* newBullet = new cBullet(x,Yy,z,y,p,d, kVacDist);

	liBullets.push_back(*newBullet);
}

//Fires 9 bullets in a rough square that spreads as it travels
void cBulletManager::addShotBullet(float x, float Yy, float z, float y, float p, int d)
{
	float offset = 5.0f;
	cBullet* newBullet1 = new cBullet(x,Yy,z,y,p,d,100.0f);
	cBullet* newBullet2 = new cBullet(x,Yy,z,y,p-offset,d,100.0f);
	cBullet* newBullet3 = new cBullet(x,Yy,z,y,p+offset,d,100.0f);
	cBullet* newBullet4 = new cBullet(x,Yy,z,y-offset,p,d,100.0f);
	cBullet* newBullet5 = new cBullet(x,Yy,z,y+offset,p,d,100.0f);
	cBullet* newBullet6 = new cBullet(x,Yy,z,y-offset,p-offset,d,100.0f);
	cBullet* newBullet7 = new cBullet(x,Yy,z,y-offset,p+offset,d,100.0f);
	cBullet* newBullet8 = new cBullet(x,Yy,z,y+offset,p-offset,d,100.0f);
	cBullet* newBullet9 = new cBullet(x,Yy,z,y+offset,p+offset,d,100.0f);
	cBullet* newBullet10 = new cBullet(x,Yy,z,y-offset/2,p-offset/2,d,100.0f);
	cBullet* newBullet11 = new cBullet(x,Yy,z,y-offset/2,p+offset/2,d,100.0f);
	cBullet* newBullet12 = new cBullet(x,Yy,z,y+offset/2,p-offset/2,d,100.0f);
	cBullet* newBullet13 = new cBullet(x,Yy,z,y+offset/2,p+offset/2,d,100.0f);

	liBullets.push_back(*newBullet1);
	liBullets.push_back(*newBullet2);
	liBullets.push_back(*newBullet3);
	liBullets.push_back(*newBullet4);
	liBullets.push_back(*newBullet5);
	liBullets.push_back(*newBullet6);
	liBullets.push_back(*newBullet7);
	liBullets.push_back(*newBullet8);
	liBullets.push_back(*newBullet9);
	liBullets.push_back(*newBullet10);
	liBullets.push_back(*newBullet11);
	liBullets.push_back(*newBullet12);
	liBullets.push_back(*newBullet13);

}

//Removes bullets from the list that are either dead from collision
//Or have reached the end of their lifespan
void cBulletManager::removeBullet()
{
	if(!(liBullets.empty()))
	{	
		itBul=liBullets.begin();
		for(itBul; itBul!=liBullets.end();)
		{
			cBullet *blah = &*itBul;
			
			bool test=blah->GetFired();

			if(test==false)
			{
				itBul = liBullets.erase(itBul);
			}
			else
			{
				itBul++;
			}
		}
	}

}

//Updates all the bullets locations and draws them
void cBulletManager::updateBullets(float elapsedTimeS)
{
		itBul = liBullets.begin();
		while (itBul!=liBullets.end())
		{
			itBul->Update(elapsedTimeS);
			itBul->Draw();
			itBul++;
		}
}

//Returns list of bullets
list<cBullet>* cBulletManager::GetBulletList()
{
	return &liBullets;
}

//Returns bullet list iterator
list<cBullet>::iterator* cBulletManager::GetBulletIter()
{
	return &itBul;
}


